// this script works on the star-rating app
let retryCount = 0;
let autoClickTriggered = false;

const waitForElements = setInterval(() => {
    try {
        const clickableStars = document.querySelector('div[data-oke-star-rating] .oke-is-clickable');
        const feedbackTab = document.querySelector('li.nav-item[data-scrol="customer-feedback"] a.tab-item');
        const scrollTarget = document.querySelector('#customer-feedback');
        const categoryTabSection = document.querySelector('section.as-category-tab');

        if (clickableStars && feedbackTab && scrollTarget && categoryTabSection) {
            clearInterval(waitForElements);

            clickableStars.addEventListener('click', function handleClick(e) {
                e.preventDefault();

                // Step 1: Click the "Customer Feedback" tab
                feedbackTab?.click();

                // Step 2: Scroll to the category tab section
                categoryTabSection?.scrollIntoView({ behavior: 'smooth', block: 'start' });

                // Step 3: One-time delayed auto-click
                if (!autoClickTriggered) {
                    autoClickTriggered = true;
                    setTimeout(() => {
                        clickableStars?.click(); // re-trigger only if element still exists
                    }, 2000);
                }
            });
        } else {
            retryCount++;
            if (retryCount > 20) {
                clearInterval(waitForElements);
                // Fail silently — no warnings
            }
        }
    } catch (error) {
        clearInterval(waitForElements); // Safety fallback
        // Fail silently — no logs
    }
}, 300);